package com.lc.headline.dao.impl;

import com.lc.headline.dao.BaseDao;
import com.lc.headline.dao.NewsUserDao;
import com.lc.headline.pojo.NewsUser;

import java.util.List;

/**
 * @author liuchun
 */
public class NewsUserDaoImpl  extends BaseDao implements NewsUserDao {

    @Override
    public NewsUser findUserByName(String username) {
        String sql = "select uid,username,user_pwd userPwd,nick_name nickName from news_user where username = ?";
        List<NewsUser> newsUserList = baseQuery(NewsUser.class, sql, username);
        if (newsUserList != null && newsUserList.size() > 0) {
            return newsUserList.get(0);
        } else {
            return null;
        }
    }

    @Override
    public NewsUser findUserByUid(Integer uid) {
        String sql = "select uid,username,user_pwd userPwd,nick_name nickName from news_user where uid = ?";
        List<NewsUser> newsUserList = baseQuery(NewsUser.class, sql, uid);
        if (newsUserList != null && newsUserList.size() > 0) {
            return newsUserList.get(0);
        } else {
            return null;
        }
    }

    @Override
    public Integer registUser(NewsUser newsUser) {
        String sql = "insert into news_user values(default,?,?,?)";
        return baseUpdate(sql,newsUser.getUsername(),newsUser.getUserPwd(),newsUser.getNickName());
    }
}
